/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.notaria.guerrasalas.bc;

import com.notaria.guerrasalas.be.Cliente;
import gob.satt.comun.jpa.NotFoundException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author Administrator
 */
public class ClienteDelegate extends AbstractDelegate {

    private GuerraSalasServiceLocal local;

    public ClienteDelegate() {
        local = lookupGuerraSalasServiceBean();
    }

    public Cliente buscar(Long codigo) throws NotFoundException {
        try {
            return (Cliente) local.find(codigo, Cliente.class);
        } catch (Exception e) {
            local = lookupGuerraSalasServiceBean();
            throw new NotFoundException("Buscar Cliente. " + getMensajeError(e), e);
        }
    }

    private GuerraSalasServiceLocal lookupGuerraSalasServiceBean() {
        try {
            Context c = new InitialContext();
            return (GuerraSalasServiceLocal) c.lookup("java:comp/env/GuerraSalasServiceBean");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }
}
